var app = getApp();
Page({
    data:{
        siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
        page : {
            isend : false,
            doing : false,
            doo : 'collect',
            pdata : {
                op : 'steplog',
                page : 1,
                type : 0,
            },
            waitf : 0,
            nodataf : 0,
        },
        datalist : [],
        type:[
            {"num":0,"name":"全部","type":0},
            {"num":0,"name":"","type":1},
            {"num":0,"name":"","type":2},
        ],
    },
    onLoad:function(options){
        var self = this;
        self.data.options = options;
        app.com.auth(function(user){
            app.com.getPage(self,self.data.page,0,function(res){
                var data = res.data.data;
                self.setData({
                   datalist : data.list,
                   params : res.data.data.params,
                },function(){
                    self.setData({
                        inited : true,
                        'type[1].name' : self.data.params.goodbname,
                        'type[2].name' : self.data.params.shopbname,
                    });
                });

            },false,function(res){
                app.com.alert(res.data.message);
            });
        });

        wx.setNavigationBarTitle({
            title:  '足迹',
        });

    },
    onReachBottom : function(){
        var self = this;
        app.com.getPage(self,self.data.page,0,function(res){
            self.setData({
                datalist : self.data.datalist.concat(res.data.data.list)
            });
        });
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.data.isdown = true;
        this.setData({
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0
        });
        this.onLoad( this.data.options );
        this.data.isdown = false;
        wx.stopPullDownRefresh();
    },
    open : function(){
        var self = this;
        self.setData({
            open : !self.data.open
        })
    },
    onChange : function(e){
        var self = this;

        if( self.data.ising || e.detail.name == self.data.page.pdata.type ) return false;
        self.data.ising = true;

        self.setData({
            'page.pdata.type' : e.detail.name,
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0
        });

        app.com.getPage(self,self.data.page,20,function(res){
            self.setData({
                datalist : res.data.data.list,
                open : false,
            });
        });

        self.data.ising = false;
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e,this.data.tid );
    },
    redirectto : function( e ){
        app.com.redirectto( e,this.data.tid );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    showkefuimg : function(e){
        app.com.alert('长按图片识别二维码联系客服',function(){
            wx.previewImage({
                current: e.currentTarget.dataset.img,
                urls: [e.currentTarget.dataset.img]
            });
        });
    },
    copy(e){
        wx.setClipboardData({
            data : e.currentTarget.dataset.copy
        })
    }

})